﻿namespace Fiddler
{
    using System;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Windows.Forms;

    internal class UIComposer : UserControl
    {
        private static bool bLoadedScratch = false;
        private Button btnBuilderExecute;
        private Button btnTearOff;
        private CheckBox cbAutoAuthenticate;
        private CheckBox cbFixContentLength;
        private CheckBox cbFollowRedirects;
        private CheckBox cbSelectBuilderResult;
        private ComboBox cbxBuilderHTTPVersion;
        private ComboBox cbxBuilderMethod;
        private ComboBox cbxBuilderURL;
        private IContainer components;
        private static DateTime dtLastDblClick;
        private static Form frmFloatingBuilder = null;
        private GroupBox gbRequestOptions;
        private GroupBox gbUIOptions;
        private Label label1;
        private Label lblBuilderRequestBody;
        private Label lblBuilderRequestHeaders;
        private Label lblHintBuilder;
        private Label lblTearoff;
        private LinkLabel linkUpload;
        private LinkLabel lnkBuilderHelp;
        private static UIComposer oRequestBuilder;
        private TabPage pageOptions;
        private TabPage pageParsed;
        private TabPage pageRaw;
        private TabPage pageScratch;
        private static Rectangle rectLastDblClick;
        private static Size sizeDblClickArea;
        private TabControl tabsBuilder;
        private TextBox txtBuilderRequestBody;
        private TextBox txtBuilderRequestHeaders;
        private TextBox txtRaw;
        private TextBox txtScratch;

        private UIComposer()
        {
            this.InitializeComponent();
            this.cbxBuilderHTTPVersion.SelectedIndex = 2;
            this.cbxBuilderMethod.SelectedIndex = 0;
            this.AllowDrop = true;
            base.DragEnter += new DragEventHandler(this.oRequestBuilder_DragEnter);
            base.DragLeave += new EventHandler(this.RequestBuilder_DragLeave);
            base.DragDrop += new DragEventHandler(this.RequestBuilder_DragDrop);
            this.cbFollowRedirects.Checked = FiddlerApplication.Prefs.GetBoolPref("fiddler.composer.followredirects", true);
            this.cbAutoAuthenticate.Checked = FiddlerApplication.Prefs.GetBoolPref("fiddler.composer.autoauth", false);
            this.cbSelectBuilderResult.Checked = FiddlerApplication.Prefs.GetBoolPref("fiddler.composer.inspectsession", false);
            this.txtScratch.Font = new Font(this.txtScratch.Font.FontFamily, CONFIG.flFontSize);
            this.txtRaw.Font = new Font(this.txtRaw.Font.FontFamily, CONFIG.flFontSize);
            this.txtBuilderRequestHeaders.Font = new Font(this.txtBuilderRequestHeaders.Font.FontFamily, CONFIG.flFontSize);
            this.txtBuilderRequestBody.Font = new Font(this.txtBuilderRequestBody.Font.FontFamily, CONFIG.flFontSize);
            if (CONFIG.flFontSize >= 11f)
            {
                this.cbxBuilderURL.Font = new Font(this.cbxBuilderURL.Font.FontFamily, 11f);
                this.cbxBuilderMethod.Font = new Font(this.cbxBuilderURL.Font.FontFamily, 11f);
                this.cbxBuilderHTTPVersion.Font = new Font(this.cbxBuilderHTTPVersion.Font.FontFamily, 11f);
            }
        }

        private bool actSendRawRequest(bool bBreakRequest)
        {
            try
            {
                string text = this.txtRaw.Text;
                bool flag = bBreakRequest || this.cbSelectBuilderResult.Checked;
                if ((((flag || this.cbFixContentLength.Checked) || this.cbAutoAuthenticate.Checked) || this.cbFollowRedirects.Checked) || CONFIG.bIsViewOnly)
                {
                    StringDictionary oNewFlags = new StringDictionary();
                    if (bBreakRequest)
                    {
                        oNewFlags["x-breakrequest"] = "Builder";
                    }
                    if (flag)
                    {
                        oNewFlags["x-Builder-Inspect"] = "1";
                    }
                    if (this.cbAutoAuthenticate.Checked)
                    {
                        oNewFlags["x-AutoAuth"] = FiddlerApplication.Prefs.GetStringPref("fiddler.composer.AutoAuthCreds", "(default)");
                    }
                    if (this.cbFollowRedirects.Checked)
                    {
                        oNewFlags["x-Builder-MaxRedir"] = FiddlerApplication.Prefs.GetInt32Pref("fiddler.composer.followredirects.max", 10).ToString();
                    }
                    if (this.cbFixContentLength.Checked)
                    {
                        oNewFlags["x-Builder-FixContentLength"] = "1";
                    }
                    FiddlerApplication.oProxy.InjectCustomRequest(text, oNewFlags);
                }
                else
                {
                    FiddlerApplication.oProxy.InjectCustomRequest(text);
                }
                return true;
            }
            catch (Exception exception)
            {
                FiddlerApplication.DoNotifyUser(exception.Message, "Custom Request Failed");
                return false;
            }
        }

        private bool actSendRequestFromWizard(bool bBreakRequest)
        {
            if (this.cbxBuilderURL.Text != this.cbxBuilderURL.Text.Trim())
            {
                this.cbxBuilderURL.Text = this.cbxBuilderURL.Text.Trim();
            }
            this.cbxBuilderURL.DroppedDown = false;
            this.cbxBuilderMethod.Text = this.cbxBuilderMethod.Text.Trim();
            this.cbxBuilderHTTPVersion.Text = this.cbxBuilderHTTPVersion.Text.Trim();
            if (!this.cbxBuilderURL.Text.StartsWith("ftp://") && !this.cbxBuilderURL.Text.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                if (this.cbxBuilderURL.Text.Contains("://"))
                {
                    MessageBox.Show("Only FTP://, HTTP://, and HTTPS:// URLs are supported.\n\nInvalid URI: " + this.cbxBuilderURL.Text, "Invalid URI");
                    return false;
                }
                this.cbxBuilderURL.Text = "http://" + this.cbxBuilderURL.Text;
            }
            if (!this.cbxBuilderURL.Items.Contains(this.cbxBuilderURL.Text))
            {
                this.cbxBuilderURL.Items.Add(this.cbxBuilderURL.Text);
            }
            bool flag = this.cbxBuilderURL.Text.Contains("#");
            string format = "d";
            int result = 0;
            int num2 = 10;
            if (flag)
            {
                string s = string.Empty;
                string str2 = frmPrompt.GetUserString("Sequential Requests Starting At", "# symbols in URL and Referer will be replaced by numbers. Prepend leading 0s if fixed-width padding is desired. Start numbers at:", "0", true);
                if (str2 == null)
                {
                    flag = false;
                }
                else
                {
                    str2 = str2.Trim();
                    if (str2.StartsWith("0") && (str2 != "0"))
                    {
                        format = "d" + str2.Length;
                    }
                }
                if (flag)
                {
                    s = frmPrompt.GetUserString("Sequential Requests Ending At", "End numbers at: ", "10", true);
                    if (s == null)
                    {
                        flag = false;
                    }
                }
                if (flag && (!int.TryParse(str2, out result) || !int.TryParse(s, out num2)))
                {
                    flag = false;
                }
            }
            try
            {
                StringBuilder builder;
                byte[] bytes;
            Label_0206:
                builder = new StringBuilder(0x400);
                string text = this.cbxBuilderURL.Text;
                if (flag)
                {
                    text = text.Replace("#", result.ToString(format));
                }
                builder.AppendFormat("{0} {1} {2}\r\n", this.cbxBuilderMethod.Text, text, this.cbxBuilderHTTPVersion.Text);
                builder.Append(this.txtBuilderRequestHeaders.Text.Trim());
                builder.Append("\r\n\r\n");
                HTTPRequestHeaders oHeaders = Parser.ParseRequest(builder.ToString());
                builder = null;
                Encoding oEncForText = Utilities.getEntityBodyEncoding(oHeaders, null);
                if (this.txtBuilderRequestBody.Text.IndexOf("<@INCLUDE", StringComparison.OrdinalIgnoreCase) < 0)
                {
                    bytes = oEncForText.GetBytes(this.txtBuilderRequestBody.Text);
                }
                else
                {
                    bytes = GetComposedUpload(this.txtBuilderRequestBody.Text, oEncForText);
                }
                string sString = text;
                int index = sString.IndexOf("//", StringComparison.Ordinal);
                if (index > -1)
                {
                    sString = sString.Substring(index + 2);
                }
                if (text.StartsWith("ftp", StringComparison.OrdinalIgnoreCase))
                {
                    sString = Utilities.TrimBefore(sString, '@');
                }
                int length = sString.IndexOfAny(new char[] { '/', '?' });
                if (length > -1)
                {
                    sString = sString.Substring(0, length).ToLower();
                }
                oHeaders["Host"] = sString;
                if ((this.cbFixContentLength.Checked && (oHeaders.Exists("Content-Length") || (bytes.Length > 0))) && !oHeaders.ExistsAndContains("Transfer-Encoding", "chunked"))
                {
                    oHeaders["Content-Length"] = bytes.Length.ToString();
                }
                this.txtBuilderRequestHeaders.Text = oHeaders.ToString(false, false);
                if (oHeaders.ExistsAndContains("Fiddler-Encoding", "base64"))
                {
                    oHeaders.Remove("Fiddler-Encoding");
                    if ((bytes != null) && (bytes.Length > 0))
                    {
                        bytes = Convert.FromBase64String(Encoding.ASCII.GetString(bytes));
                        if (!oHeaders.Exists("Transfer-Encoding"))
                        {
                            oHeaders["Content-Length"] = bytes.LongLength.ToString();
                        }
                    }
                }
                Session session = new Session((HTTPRequestHeaders) oHeaders.Clone(), bytes);
                session.SetBitFlag(SessionFlags.RequestGeneratedByFiddler, true);
                session.oFlags["x-From-Builder"] = "true";
                string str6 = session.oRequest.headers["Fiddler-Host"];
                if (!string.IsNullOrEmpty(str6))
                {
                    session.oRequest.headers.Remove("Fiddler-Host");
                    session.oFlags["X-OverrideHost"] = str6;
                    session.oFlags["x-OverrideGateway"] = "DIRECT";
                    session.oFlags["X-IgnoreCertCNMismatch"] = "Overrode HOST";
                }
                bool flag2 = this.cbSelectBuilderResult.Checked;
                if (bBreakRequest)
                {
                    session.oFlags["x-breakrequest"] = "Builder";
                    flag2 = true;
                }
                if (flag)
                {
                    if (session.oRequest.headers.ExistsAndContains("Referer", "#"))
                    {
                        session.oRequest["Referer"] = session.oRequest["Referer"].Replace("#", result.ToString(format));
                    }
                }
                else if (flag2)
                {
                    session.oFlags["x-Builder-Inspect"] = "1";
                }
                if (this.cbAutoAuthenticate.Checked)
                {
                    session.oFlags["x-AutoAuth"] = FiddlerApplication.Prefs.GetStringPref("fiddler.composer.AutoAuthCreds", "(default)");
                }
                if (this.cbFollowRedirects.Checked)
                {
                    session.oFlags["x-Builder-MaxRedir"] = FiddlerApplication.Prefs.GetInt32Pref("fiddler.composer.followredirects.max", 10).ToString();
                }
                ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(session.Execute), null);
                if (flag && (result < num2))
                {
                    result++;
                    goto Label_0206;
                }
                return true;
            }
            catch (Exception exception)
            {
                FiddlerApplication.DoNotifyUser(exception.Message, "Custom Request Failed");
                return false;
            }
        }

        private bool actSendScratchRequest(bool bBreakRequest)
        {
            try
            {
                string uriString = this.txtScratch.SelectedText.Trim();
                if (!uriString.Contains(" ") && uriString.Contains("://"))
                {
                    Uri uri = new Uri(uriString);
                    string host = uri.Host;
                    uriString = string.Format("GET {0} HTTP/1.1\r\nHost: {1}\r\n\r\n", uriString, host);
                }
                if (!uriString.Contains("\r\n\r\n"))
                {
                    uriString = uriString + "\r\n\r\n";
                }
                bool flag = bBreakRequest || this.cbSelectBuilderResult.Checked;
                StringDictionary oNewFlags = new StringDictionary();
                if (bBreakRequest)
                {
                    oNewFlags["x-breakrequest"] = "Builder";
                }
                if (flag)
                {
                    oNewFlags["x-Builder-Inspect"] = "1";
                }
                if (this.cbAutoAuthenticate.Checked)
                {
                    oNewFlags["x-AutoAuth"] = FiddlerApplication.Prefs.GetStringPref("fiddler.composer.AutoAuthCreds", "(default)");
                }
                if (this.cbFollowRedirects.Checked)
                {
                    oNewFlags["x-Builder-MaxRedir"] = FiddlerApplication.Prefs.GetInt32Pref("fiddler.composer.followredirects.max", 10).ToString();
                }
                if (this.cbFixContentLength.Checked)
                {
                    oNewFlags["x-Builder-FixContentLength"] = "1";
                }
                FiddlerApplication.oProxy.InjectCustomRequest(uriString, oNewFlags);
                return true;
            }
            catch (Exception exception)
            {
                FiddlerApplication.DoNotifyUser(exception.Message, "Custom Request Failed");
                return false;
            }
        }

        internal static bool AddSessionsToScratch(Session[] oSessions)
        {
            EnsureReady();
            byte[] bytes = Encoding.UTF8.GetBytes("\r\n==========================================================\r\n\r\n");
            MemoryStream oFS = new MemoryStream();
            foreach (Session session in oSessions)
            {
                oFS.Write(bytes, 0, bytes.Length);
                session.WriteRequestToStream(session.HTTPMethodIs("CONNECT"), true, true, oFS);
            }
            string text = Encoding.UTF8.GetString(oFS.GetBuffer());
            oRequestBuilder.txtScratch.AppendText(text);
            oRequestBuilder.txtScratch.Modified = true;
            return true;
        }

        internal static bool AddTextToScratch(string sText)
        {
            EnsureReady();
            oRequestBuilder.txtScratch.AppendText(sText);
            return true;
        }

        private void btnBuilderExecute_Click(object sender, EventArgs e)
        {
            bool bBreakRequest = Keys.Shift == (Control.ModifierKeys & Keys.Shift);
            if (this.tabsBuilder.SelectedTab == this.pageRaw)
            {
                this.actSendRawRequest(bBreakRequest);
            }
            else if (this.tabsBuilder.SelectedTab == this.pageScratch)
            {
                if (this.txtScratch.SelectionLength < 10)
                {
                    MessageBox.Show("In the box below, please highlight the complete HTTP request to be sent before pressing Execute.", "Invalid Selection");
                }
                else
                {
                    this.actSendScratchRequest(bBreakRequest);
                }
            }
            else
            {
                this.actSendRequestFromWizard(bBreakRequest);
            }
        }

        private void btnTearOff_Click(object sender, EventArgs e)
        {
            frmFloatingBuilder = new Form();
            frmFloatingBuilder.FormBorderStyle = FormBorderStyle.SizableToolWindow;
            frmFloatingBuilder.Width = 0x1d8;
            frmFloatingBuilder.Height = 500;
            frmFloatingBuilder.StartPosition = FormStartPosition.Manual;
            frmFloatingBuilder.Left = (base.Left + base.Width) - 500;
            frmFloatingBuilder.Top = base.Top + 100;
            frmFloatingBuilder.Text = "Composer";
            FiddlerApplication.UI.tabsViews.TabPages.Remove(FiddlerApplication.UI.pageBuilder);
            frmFloatingBuilder.Controls.Add(this);
            this.cbSelectBuilderResult.Checked = true;
            this.gbUIOptions.Visible = false;
            frmFloatingBuilder.Icon = FiddlerApplication.UI.Icon;
            frmFloatingBuilder.FormClosing += new FormClosingEventHandler(this.frmFloatingBuilder_FormClosing);
            frmFloatingBuilder.Show(FiddlerApplication.UI);
        }

        private void Builder_BodyOrMethodChanged(object sender, EventArgs e)
        {
            if (Utilities.HTTPMethodAllowsBody(this.cbxBuilderMethod.Text.Trim().ToUpper()))
            {
                this.txtBuilderRequestBody.BackColor = Color.FromKnownColor(KnownColor.Window);
            }
            else
            {
                this.txtBuilderRequestBody.BackColor = (this.txtBuilderRequestBody.Text.Length > 0) ? Color.Red : Color.FromKnownColor(KnownColor.Control);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        internal static void EnsureReady()
        {
            if (oRequestBuilder == null)
            {
                oRequestBuilder = new UIComposer();
                oRequestBuilder.Parent = FiddlerApplication.UI.pageBuilder;
                oRequestBuilder.Dock = DockStyle.Fill;
                sizeDblClickArea = new Size(SystemInformation.DoubleClickSize.Width / 2, SystemInformation.DoubleClickSize.Height / 2);
            }
        }

        private void EnsureScratch()
        {
            if (!bLoadedScratch)
            {
                bLoadedScratch = true;
                try
                {
                    this.txtScratch.Text = File.ReadAllText(CONFIG.GetPath("Root") + "Composer_Scratch.txt", Encoding.UTF8);
                }
                catch
                {
                }
            }
        }

        internal static void EnsureShowing()
        {
            if (FiddlerApplication.UI.tabsViews.Contains(FiddlerApplication.UI.pageBuilder))
            {
                FiddlerApplication.UI.tabsViews.SelectedTab = FiddlerApplication.UI.pageBuilder;
            }
            else if (frmFloatingBuilder != null)
            {
                frmFloatingBuilder.BringToFront();
            }
        }

        internal static bool FillUIFromSession(Session oSession)
        {
            EnsureReady();
            oRequestBuilder.cbxBuilderHTTPVersion.Text = oSession.oRequest.headers.HTTPVersion;
            oRequestBuilder.cbxBuilderMethod.Text = oSession.oRequest.headers.HTTPMethod;
            oRequestBuilder.cbxBuilderURL.Text = oSession.fullUrl;
            bool flag = ((oSession.requestBodyBytes != null) && !oSession.HTTPMethodIs("CONNECT")) && Utilities.arrayContainsNonText(oSession.requestBodyBytes);
            if (oSession.oRequest.headers != null)
            {
                HTTPRequestHeaders headers = (HTTPRequestHeaders) oSession.oRequest.headers.Clone();
                if (flag)
                {
                    headers["Fiddler-Encoding"] = "base64";
                }
                oRequestBuilder.txtBuilderRequestHeaders.Text = headers.ToString(false, false);
                oRequestBuilder.txtRaw.Text = headers.ToString(true, true);
            }
            else
            {
                oRequestBuilder.txtBuilderRequestHeaders.Clear();
                oRequestBuilder.txtRaw.Clear();
            }
            if ((oSession.requestBodyBytes != null) && !oSession.HTTPMethodIs("CONNECT"))
            {
                if (flag)
                {
                    oRequestBuilder.txtBuilderRequestBody.Text = Convert.ToBase64String(oSession.requestBodyBytes);
                }
                else
                {
                    oRequestBuilder.txtBuilderRequestBody.Text = Utilities.GetStringFromArrayRemovingBOM(oSession.requestBodyBytes, oSession.GetRequestBodyEncoding());
                }
                oRequestBuilder.txtRaw.Text = oRequestBuilder.txtRaw.Text + oRequestBuilder.txtBuilderRequestBody.Text;
            }
            else
            {
                oRequestBuilder.txtBuilderRequestBody.Clear();
            }
            return true;
        }

        private void FloodSelectText()
        {
            int lineFromCharIndex = this.txtScratch.GetLineFromCharIndex(this.txtScratch.SelectionStart);
            int firstCharIndexFromLine = this.txtScratch.GetFirstCharIndexFromLine(lineFromCharIndex);
            int num3 = this.txtScratch.Lines[lineFromCharIndex].Length + 2;
            int iLineNum = lineFromCharIndex;
            while (--iLineNum >= 0)
            {
                if (!this.isValidLine(iLineNum, false))
                {
                    break;
                }
                firstCharIndexFromLine = this.txtScratch.GetFirstCharIndexFromLine(iLineNum);
                num3 += 2 + this.txtScratch.Lines[iLineNum].Length;
            }
            bool bBreakOnlyOnEqualLine = false;
            if (this.txtScratch.Text[firstCharIndexFromLine] == 'P')
            {
                bBreakOnlyOnEqualLine = true;
            }
            int num5 = lineFromCharIndex;
            while (++num5 < this.txtScratch.Lines.Length)
            {
                if (!this.isValidLine(num5, bBreakOnlyOnEqualLine))
                {
                    break;
                }
                num3 += 2 + this.txtScratch.Lines[num5].Length;
            }
            this.txtScratch.SelectionStart = firstCharIndexFromLine;
            this.txtScratch.SelectionLength = num3;
        }

        private void frmFloatingBuilder_FormClosing(object sender, FormClosingEventArgs e)
        {
            FiddlerApplication.UI.tabsViews.Controls.Add(FiddlerApplication.UI.pageBuilder);
            FiddlerApplication.UI.pageBuilder.Dock = DockStyle.Fill;
            oRequestBuilder.Parent = FiddlerApplication.UI.pageBuilder;
            oRequestBuilder.Dock = DockStyle.Fill;
            this.gbUIOptions.Visible = true;
            this.cbSelectBuilderResult.Checked = false;
            frmFloatingBuilder = null;
        }

        private static byte[] GetComposedUpload(string sUpload, Encoding oEncForText)
        {
            MemoryStream stream = new MemoryStream();
            try
            {
                int startIndex = 0;
                for (int i = sUpload.IndexOf("<@INCLUDE", startIndex, StringComparison.OrdinalIgnoreCase); i > -1; i = sUpload.IndexOf("<@INCLUDE", startIndex, StringComparison.OrdinalIgnoreCase))
                {
                    if (i > startIndex)
                    {
                        byte[] bytes = oEncForText.GetBytes(sUpload.Substring(startIndex, i - startIndex));
                        stream.Write(bytes, 0, bytes.Length);
                        startIndex += i - startIndex;
                    }
                    while ((i < sUpload.Length) && ('*' != sUpload[i]))
                    {
                        i++;
                    }
                    if (i < sUpload.Length)
                    {
                        i++;
                        int index = sUpload.IndexOf('*', i);
                        byte[] buffer = File.ReadAllBytes(sUpload.Substring(i, index - i));
                        stream.Write(buffer, 0, buffer.Length);
                        startIndex = sUpload.IndexOf("@>", index);
                        if (startIndex < 0)
                        {
                            startIndex = sUpload.Length;
                        }
                        else
                        {
                            startIndex += 2;
                        }
                    }
                }
                if (startIndex < sUpload.Length)
                {
                    byte[] buffer3 = oEncForText.GetBytes(sUpload.Substring(startIndex, sUpload.Length - startIndex));
                    stream.Write(buffer3, 0, buffer3.Length);
                }
            }
            catch (Exception exception)
            {
                FiddlerApplication.ReportException(exception);
            }
            return stream.ToArray();
        }

        private void HandleSelectAllKeydown(object sender, KeyEventArgs e)
        {
            if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.A))
            {
                (sender as TextBox).SelectAll();
                e.SuppressKeyPress = true;
            }
        }

        private void InitializeComponent()
        {
            this.btnBuilderExecute = new Button();
            this.lblHintBuilder = new Label();
            this.tabsBuilder = new TabControl();
            this.pageParsed = new TabPage();
            this.cbxBuilderURL = new ComboBox();
            this.linkUpload = new LinkLabel();
            this.txtBuilderRequestHeaders = new TextBox();
            this.lnkBuilderHelp = new LinkLabel();
            this.txtBuilderRequestBody = new TextBox();
            this.lblBuilderRequestBody = new Label();
            this.lblBuilderRequestHeaders = new Label();
            this.cbxBuilderHTTPVersion = new ComboBox();
            this.cbxBuilderMethod = new ComboBox();
            this.pageRaw = new TabPage();
            this.txtRaw = new TextBox();
            this.pageScratch = new TabPage();
            this.txtScratch = new TextBox();
            this.label1 = new Label();
            this.pageOptions = new TabPage();
            this.gbRequestOptions = new GroupBox();
            this.cbAutoAuthenticate = new CheckBox();
            this.cbFollowRedirects = new CheckBox();
            this.cbFixContentLength = new CheckBox();
            this.cbSelectBuilderResult = new CheckBox();
            this.gbUIOptions = new GroupBox();
            this.lblTearoff = new Label();
            this.btnTearOff = new Button();
            this.tabsBuilder.SuspendLayout();
            this.pageParsed.SuspendLayout();
            this.pageRaw.SuspendLayout();
            this.pageScratch.SuspendLayout();
            this.pageOptions.SuspendLayout();
            this.gbRequestOptions.SuspendLayout();
            this.gbUIOptions.SuspendLayout();
            base.SuspendLayout();
            //this.btnBuilderExecute.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnBuilderExecute.Location = new Point(540, 3);
            this.btnBuilderExecute.Name = "btnBuilderExecute";
            this.btnBuilderExecute.Size = new Size(0x3e, 0x26);
            this.btnBuilderExecute.TabIndex = 14;
            this.btnBuilderExecute.Text = "E&xecute";
            this.btnBuilderExecute.Click += new EventHandler(this.btnBuilderExecute_Click);
            this.lblHintBuilder.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.lblHintBuilder.BackColor = Color.Gray;
            this.lblHintBuilder.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.lblHintBuilder.ForeColor = Color.White;
            this.lblHintBuilder.Location = new Point(3, 3);
            this.lblHintBuilder.Name = "lblHintBuilder";
            this.lblHintBuilder.Padding = new Padding(4);
            this.lblHintBuilder.Size = new Size(0x217, 0x26);
            this.lblHintBuilder.TabIndex = 0x11;
            this.lblHintBuilder.Text = "Use this page to compose a Request. You can clone a prior request by dragging and dropping a session from the Web Sessions list.";
            this.lblHintBuilder.TextAlign = ContentAlignment.MiddleLeft;
            this.tabsBuilder.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.tabsBuilder.Controls.Add(this.pageParsed);
            this.tabsBuilder.Controls.Add(this.pageRaw);
            this.tabsBuilder.Controls.Add(this.pageScratch);
            this.tabsBuilder.Controls.Add(this.pageOptions);
            this.tabsBuilder.Location = new Point(3, 0x2c);
            this.tabsBuilder.Multiline = true;
            this.tabsBuilder.Name = "tabsBuilder";
            this.tabsBuilder.SelectedIndex = 0;
            this.tabsBuilder.Size = new Size(600, 0x1bb);
            this.tabsBuilder.TabIndex = 0;
            this.tabsBuilder.SelectedIndexChanged += new EventHandler(this.tabsBuilder_SelectedIndexChanged);
            this.pageParsed.Controls.Add(this.cbxBuilderHTTPVersion);
            this.pageParsed.Controls.Add(this.cbxBuilderURL);
            this.pageParsed.Controls.Add(this.linkUpload);
            this.pageParsed.Controls.Add(this.txtBuilderRequestHeaders);
            this.pageParsed.Controls.Add(this.lnkBuilderHelp);
            this.pageParsed.Controls.Add(this.txtBuilderRequestBody);
            this.pageParsed.Controls.Add(this.lblBuilderRequestBody);
            this.pageParsed.Controls.Add(this.lblBuilderRequestHeaders);
            this.pageParsed.Controls.Add(this.cbxBuilderMethod);
            this.pageParsed.Location = new Point(4, 0x16);
            this.pageParsed.Name = "pageParsed";
            this.pageParsed.Padding = new Padding(3);
            this.pageParsed.Size = new Size(0x250, 0x1a1);
            this.pageParsed.TabIndex = 0;
            this.pageParsed.Text = "Parsed";
            this.pageParsed.UseVisualStyleBackColor = true;
            this.cbxBuilderURL.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.cbxBuilderURL.FormattingEnabled = true;
            this.cbxBuilderURL.Location = new Point(0x61, 8);
            this.cbxBuilderURL.Name = "cbxBuilderURL";
            this.cbxBuilderURL.Size = new Size(0x185, 0x15);
            this.cbxBuilderURL.TabIndex = 1;
            this.cbxBuilderURL.Text = "http://www.example.com/";
            this.cbxBuilderURL.TextChanged += new EventHandler(this.txtBuilderURL_TextChanged);
            this.cbxBuilderURL.KeyDown += new KeyEventHandler(this.txtBuilderURL_KeyDown);
            this.cbxBuilderURL.KeyPress += new KeyPressEventHandler(this.txtBuilderURL_KeyPress);
            this.linkUpload.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.linkUpload.AutoSize = true;
            this.linkUpload.LinkBehavior = LinkBehavior.HoverUnderline;
            this.linkUpload.Location = new Point(0x1c8, 0x20);
            this.linkUpload.Name = "linkUpload";
            this.linkUpload.Size = new Size(0x53, 13);
            this.linkUpload.TabIndex = 0x1f;
            this.linkUpload.TabStop = true;
            this.linkUpload.Text = "[ Upload file... ]";
            this.linkUpload.TextAlign = ContentAlignment.MiddleRight;
            this.linkUpload.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkUpload_LinkClicked);
            this.txtBuilderRequestHeaders.AcceptsReturn = true;
            this.txtBuilderRequestHeaders.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtBuilderRequestHeaders.BackColor = SystemColors.Window;
            this.txtBuilderRequestHeaders.Location = new Point(7, 0x34);
            this.txtBuilderRequestHeaders.MaxLength = 0x400000;
            this.txtBuilderRequestHeaders.Multiline = true;
            this.txtBuilderRequestHeaders.Name = "txtBuilderRequestHeaders";
            this.txtBuilderRequestHeaders.ScrollBars = ScrollBars.Both;
            this.txtBuilderRequestHeaders.Size = new Size(0x242, 0xe9);
            this.txtBuilderRequestHeaders.TabIndex = 4;
            this.txtBuilderRequestHeaders.Text = "User-Agent: Fiddler";
            this.txtBuilderRequestHeaders.WordWrap = false;
            this.txtBuilderRequestHeaders.KeyDown += new KeyEventHandler(this.HandleSelectAllKeydown);
            this.lnkBuilderHelp.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lnkBuilderHelp.AutoSize = true;
            this.lnkBuilderHelp.LinkBehavior = LinkBehavior.HoverUnderline;
            this.lnkBuilderHelp.Location = new Point(0x222, 0x20);
            this.lnkBuilderHelp.Name = "lnkBuilderHelp";
            this.lnkBuilderHelp.Size = new Size(40, 13);
            this.lnkBuilderHelp.TabIndex = 30;
            this.lnkBuilderHelp.TabStop = true;
            this.lnkBuilderHelp.Text = "Help...";
            this.lnkBuilderHelp.TextAlign = ContentAlignment.MiddleRight;
            this.lnkBuilderHelp.LinkClicked += new LinkLabelLinkClickedEventHandler(this.lnkBuilderHelp_LinkClicked);
            this.txtBuilderRequestBody.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.txtBuilderRequestBody.BackColor = SystemColors.Control;
            this.txtBuilderRequestBody.Location = new Point(7, 0x12e);
            this.txtBuilderRequestBody.MaxLength = 0x1000000;
            this.txtBuilderRequestBody.Multiline = true;
            this.txtBuilderRequestBody.Name = "txtBuilderRequestBody";
            this.txtBuilderRequestBody.ScrollBars = ScrollBars.Both;
            this.txtBuilderRequestBody.Size = new Size(0x242, 0x6b);
            this.txtBuilderRequestBody.TabIndex = 6;
            this.txtBuilderRequestBody.WordWrap = false;
            this.txtBuilderRequestBody.TextChanged += new EventHandler(this.Builder_BodyOrMethodChanged);
            this.txtBuilderRequestBody.KeyDown += new KeyEventHandler(this.HandleSelectAllKeydown);
            this.lblBuilderRequestBody.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.lblBuilderRequestBody.Location = new Point(7, 0x120);
            this.lblBuilderRequestBody.Name = "lblBuilderRequestBody";
            this.lblBuilderRequestBody.Size = new Size(0x88, 14);
            this.lblBuilderRequestBody.TabIndex = 5;
            this.lblBuilderRequestBody.Text = "Request Body";
            this.lblBuilderRequestHeaders.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.lblBuilderRequestHeaders.Location = new Point(7, 0x26);
            this.lblBuilderRequestHeaders.Name = "lblBuilderRequestHeaders";
            this.lblBuilderRequestHeaders.Size = new Size(0x88, 0x10);
            this.lblBuilderRequestHeaders.TabIndex = 3;
            this.lblBuilderRequestHeaders.Text = "Request Headers";
            this.cbxBuilderHTTPVersion.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.cbxBuilderHTTPVersion.Items.AddRange(new object[] { "HTTP/2.0", "HTTP/1.2", "HTTP/1.1", "HTTP/1.0", "HTTP/0.9" });
            this.cbxBuilderHTTPVersion.Location = new Point(0x1ec, 8);
            this.cbxBuilderHTTPVersion.Name = "cbxBuilderHTTPVersion";
            this.cbxBuilderHTTPVersion.Size = new Size(0x5d, 0x15);
            this.cbxBuilderHTTPVersion.TabIndex = 2;
            this.cbxBuilderMethod.Items.AddRange(new object[] { 
                "GET", "POST", "PUT", "HEAD", "TRACE", "DELETE", "SEARCH", "CONNECT", "PROPFIND", "PROPPATCH", "PATCH", "MKCOL", "COPY", "MOVE", "LOCK", "UNLOCK", 
                "OPTIONS"
             });
            this.cbxBuilderMethod.Location = new Point(7, 8);
            this.cbxBuilderMethod.Name = "cbxBuilderMethod";
            this.cbxBuilderMethod.Size = new Size(0x56, 0x15);
            this.cbxBuilderMethod.TabIndex = 0;
            this.cbxBuilderMethod.TextChanged += new EventHandler(this.Builder_BodyOrMethodChanged);
            this.pageRaw.Controls.Add(this.txtRaw);
            this.pageRaw.Location = new Point(4, 0x16);
            this.pageRaw.Name = "pageRaw";
            this.pageRaw.Padding = new Padding(3);
            this.pageRaw.Size = new Size(0x250, 0x1a1);
            this.pageRaw.TabIndex = 1;
            this.pageRaw.Text = "Raw";
            this.pageRaw.UseVisualStyleBackColor = true;
            this.txtRaw.AcceptsReturn = true;
            this.txtRaw.BackColor = SystemColors.Window;
            this.txtRaw.Dock = DockStyle.Fill;
            this.txtRaw.Location = new Point(3, 3);
            this.txtRaw.MaxLength = 0x400000;
            this.txtRaw.Multiline = true;
            this.txtRaw.Name = "txtRaw";
            this.txtRaw.ScrollBars = ScrollBars.Both;
            this.txtRaw.Size = new Size(0x24a, 0x19b);
            this.txtRaw.TabIndex = 0x1c;
            this.txtRaw.WordWrap = false;
            this.txtRaw.KeyDown += new KeyEventHandler(this.HandleSelectAllKeydown);
            this.pageScratch.Controls.Add(this.txtScratch);
            this.pageScratch.Controls.Add(this.label1);
            this.pageScratch.Location = new Point(4, 0x16);
            this.pageScratch.Name = "pageScratch";
            this.pageScratch.Padding = new Padding(3);
            this.pageScratch.Size = new Size(0x250, 0x1a1);
            this.pageScratch.TabIndex = 3;
            this.pageScratch.Text = "Scratchpad";
            this.pageScratch.UseVisualStyleBackColor = true;
            this.txtScratch.AcceptsReturn = true;
            this.txtScratch.BackColor = SystemColors.Window;
            this.txtScratch.Dock = DockStyle.Fill;
            this.txtScratch.HideSelection = false;
            this.txtScratch.Location = new Point(3, 0x29);
            this.txtScratch.MaxLength = 0x400000;
            this.txtScratch.Multiline = true;
            this.txtScratch.Name = "txtScratch";
            this.txtScratch.ScrollBars = ScrollBars.Both;
            this.txtScratch.Size = new Size(0x24a, 0x175);
            this.txtScratch.TabIndex = 0x1d;
            this.txtScratch.WordWrap = false;
            this.txtScratch.MouseClick += new MouseEventHandler(this.txtScratch_MouseClick);
            this.txtScratch.KeyDown += new KeyEventHandler(this.HandleSelectAllKeydown);
            this.txtScratch.MouseDoubleClick += new MouseEventHandler(this.txtScratch_MouseDoubleClick);
            this.label1.BackColor = Color.Gray;
            this.label1.Dock = DockStyle.Top;
            this.label1.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.label1.ForeColor = Color.White;
            this.label1.Location = new Point(3, 3);
            this.label1.Name = "label1";
            this.label1.Padding = new Padding(4);
            this.label1.Size = new Size(0x24a, 0x26);
            this.label1.TabIndex = 0x12;
            this.label1.Text = "Use this tab to maintain a list of Requests. Select the text of the request and press Execute to send the request.";
            this.label1.TextAlign = ContentAlignment.MiddleLeft;
            this.pageOptions.Controls.Add(this.gbRequestOptions);
            this.pageOptions.Controls.Add(this.gbUIOptions);
            this.pageOptions.Location = new Point(4, 0x16);
            this.pageOptions.Name = "pageOptions";
            this.pageOptions.Padding = new Padding(3);
            this.pageOptions.Size = new Size(0x250, 0x1a1);
            this.pageOptions.TabIndex = 2;
            this.pageOptions.Text = "Options";
            this.pageOptions.UseVisualStyleBackColor = true;
            this.gbRequestOptions.Controls.Add(this.cbAutoAuthenticate);
            this.gbRequestOptions.Controls.Add(this.cbFollowRedirects);
            this.gbRequestOptions.Controls.Add(this.cbFixContentLength);
            this.gbRequestOptions.Controls.Add(this.cbSelectBuilderResult);
            this.gbRequestOptions.Location = new Point(0x12, 0x10);
            this.gbRequestOptions.Name = "gbRequestOptions";
            this.gbRequestOptions.Size = new Size(0x184, 0x7e);
            this.gbRequestOptions.TabIndex = 0;
            this.gbRequestOptions.TabStop = false;
            this.gbRequestOptions.Text = "Request Options";
            this.cbAutoAuthenticate.AutoSize = true;
            this.cbAutoAuthenticate.Location = new Point(9, 0x59);
            this.cbAutoAuthenticate.Name = "cbAutoAuthenticate";
            this.cbAutoAuthenticate.Size = new Size(0x97, 0x11);
            this.cbAutoAuthenticate.TabIndex = 3;
            this.cbAutoAuthenticate.Text = "Automatically Authenticate";
            this.cbAutoAuthenticate.UseVisualStyleBackColor = true;
            this.cbFollowRedirects.AutoSize = true;
            this.cbFollowRedirects.Checked = true;
            this.cbFollowRedirects.CheckState = CheckState.Checked;
            this.cbFollowRedirects.Location = new Point(9, 0x42);
            this.cbFollowRedirects.Name = "cbFollowRedirects";
            this.cbFollowRedirects.Size = new Size(0x68, 0x11);
            this.cbFollowRedirects.TabIndex = 2;
            this.cbFollowRedirects.Text = "Follow Redirects";
            this.cbFollowRedirects.UseVisualStyleBackColor = true;
            this.cbFixContentLength.AutoSize = true;
            this.cbFixContentLength.Checked = true;
            this.cbFixContentLength.CheckState = CheckState.Checked;
            this.cbFixContentLength.Location = new Point(9, 0x2b);
            this.cbFixContentLength.Name = "cbFixContentLength";
            this.cbFixContentLength.Size = new Size(0x97, 0x11);
            this.cbFixContentLength.TabIndex = 1;
            this.cbFixContentLength.Text = "Fix Content-Length header";
            this.cbFixContentLength.UseVisualStyleBackColor = true;
            this.cbSelectBuilderResult.AutoSize = true;
            this.cbSelectBuilderResult.Location = new Point(9, 20);
            this.cbSelectBuilderResult.Name = "cbSelectBuilderResult";
            this.cbSelectBuilderResult.Size = new Size(0x65, 0x11);
            this.cbSelectBuilderResult.TabIndex = 0;
            this.cbSelectBuilderResult.Text = "Inspect Session";
            this.cbSelectBuilderResult.UseVisualStyleBackColor = true;
            this.gbUIOptions.Controls.Add(this.lblTearoff);
            this.gbUIOptions.Controls.Add(this.btnTearOff);
            this.gbUIOptions.Location = new Point(0x12, 0x94);
            this.gbUIOptions.Name = "gbUIOptions";
            this.gbUIOptions.Size = new Size(0x184, 100);
            this.gbUIOptions.TabIndex = 1;
            this.gbUIOptions.TabStop = false;
            this.gbUIOptions.Text = "UI Options";
            this.lblTearoff.AutoSize = true;
            this.lblTearoff.Location = new Point(6, 0x1a);
            this.lblTearoff.Name = "lblTearoff";
            this.lblTearoff.Size = new Size(0x113, 13);
            this.lblTearoff.TabIndex = 0;
            this.lblTearoff.Text = "You can \"tear off\" the Composer into a floating window.";
            this.btnTearOff.Location = new Point(9, 0x33);
            this.btnTearOff.Name = "btnTearOff";
            this.btnTearOff.Size = new Size(0x4b, 0x17);
            this.btnTearOff.TabIndex = 1;
            this.btnTearOff.Text = "Tear off";
            this.btnTearOff.UseVisualStyleBackColor = true;
            this.btnTearOff.Click += new EventHandler(this.btnTearOff_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
           // base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.tabsBuilder);
            base.Controls.Add(this.btnBuilderExecute);
            base.Controls.Add(this.lblHintBuilder);
            this.Font = new Font("Tahoma", 8.25f);
            base.Name = "RequestBuilder";
            base.Size = new Size(0x25d, 490);
            this.tabsBuilder.ResumeLayout(false);
            this.pageParsed.ResumeLayout(false);
            this.pageParsed.PerformLayout();
            this.pageRaw.ResumeLayout(false);
            this.pageRaw.PerformLayout();
            this.pageScratch.ResumeLayout(false);
            this.pageScratch.PerformLayout();
            this.pageOptions.ResumeLayout(false);
            this.gbRequestOptions.ResumeLayout(false);
            this.gbRequestOptions.PerformLayout();
            this.gbUIOptions.ResumeLayout(false);
            this.gbUIOptions.PerformLayout();
            base.ResumeLayout(false);
        }

        private bool isValidLine(int iLineNum, bool bBreakOnlyOnEqualLine)
        {
            string str = this.txtScratch.Lines[iLineNum];
            if (!bBreakOnlyOnEqualLine && (str.Length < 1))
            {
                return false;
            }
            if (str.StartsWith("=") && str.EndsWith("="))
            {
                return false;
            }
            return true;
        }

        private void linkUpload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            bool flag = string.Equals(this.cbxBuilderMethod.Text.Trim(), "PUT", StringComparison.OrdinalIgnoreCase);
            string[] strArray = Utilities.ObtainFilenames(string.Format("Select file{0} for upload", flag ? string.Empty : "(s)"), "All files (*.*)|*.*", null, !flag);
            if (strArray != null)
            {
                if (flag)
                {
                    string path = strArray[0];
                    string str2 = Utilities.ContentTypeForFileExtension(Path.GetExtension(path));
                    if (string.IsNullOrEmpty(str2))
                    {
                        str2 = "application/octet-stream";
                    }
                    this.txtBuilderRequestHeaders.Text = string.Format("Content-Type: {0}\r\n{1}", str2, this.txtBuilderRequestHeaders.Text);
                    this.txtBuilderRequestBody.Text = string.Format("<@INCLUDE *{0}*@>", path);
                }
                else
                {
                    this.cbxBuilderMethod.Text = "POST";
                    string str3 = "-------------------------acebdf13572468";
                    string str4 = string.Format("Content-Type: multipart/form-data; boundary={0}\r\n", str3);
                    if (!this.txtBuilderRequestHeaders.Text.Contains(str4))
                    {
                        this.txtBuilderRequestHeaders.Text = string.Format("{0}{1}", str4, this.txtBuilderRequestHeaders.Text);
                    }
                    StringBuilder builder = new StringBuilder();
                    foreach (string str5 in strArray)
                    {
                        string str6 = Utilities.ContentTypeForFileExtension(Path.GetExtension(str5));
                        if (string.IsNullOrEmpty(str6))
                        {
                            str6 = "application/octet-stream";
                        }
                        string fileName = Path.GetFileName(str5);
                        builder.AppendFormat("--{0}\r\nContent-Disposition: form-data; name=\"fieldNameHere\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n<@INCLUDE *{3}*@>\r\n", new object[] { str3, fileName, str6, str5 });
                    }
                    builder.AppendFormat("--{0}--\r\n", str3);
                    this.txtBuilderRequestBody.Text = builder.ToString();
                }
            }
        }

        private void lnkBuilderHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Utilities.LaunchHyperlink(CONFIG.GetUrl("REDIR") + "COMPOSER");
        }

        private void oRequestBuilder_DragEnter(object sender, DragEventArgs e)
        {
            bool dataPresent = e.Data.GetDataPresent("Fiddler.Session[]");
            if ((!dataPresent && (this.tabsBuilder.SelectedTab == this.pageScratch)) && e.Data.GetDataPresent(DataFormats.Text))
            {
                dataPresent = true;
            }
            if (dataPresent)
            {
                e.Effect = DragDropEffects.Link | DragDropEffects.Copy;
                this.BackColor = Color.Lime;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void RequestBuilder_DragDrop(object sender, DragEventArgs e)
        {
            this.BackColor = Color.FromKnownColor(KnownColor.Control);
            Session[] data = (Session[]) e.Data.GetData("Fiddler.Session[]");
            if ((data != null) && (data.Length > 0))
            {
                if (this.tabsBuilder.SelectedTab == this.pageScratch)
                {
                    AddSessionsToScratch(data);
                }
                else
                {
                    FillUIFromSession(data[0]);
                }
            }
            else if ((this.tabsBuilder.SelectedTab == this.pageScratch) && e.Data.GetDataPresent(DataFormats.Text))
            {
                AddTextToScratch(Environment.NewLine + ((string) e.Data.GetData(DataFormats.Text)));
            }
        }

        private void RequestBuilder_DragLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromKnownColor(KnownColor.Control);
        }

        private void SavePreferences()
        {
            FiddlerApplication.Prefs.SetBoolPref("fiddler.composer.followredirects", this.cbFollowRedirects.Checked);
            FiddlerApplication.Prefs.SetBoolPref("fiddler.composer.autoauth", this.cbAutoAuthenticate.Checked);
            FiddlerApplication.Prefs.SetBoolPref("fiddler.composer.inspectsession", this.cbSelectBuilderResult.Checked);
            try
            {
                if (bLoadedScratch && this.txtScratch.Modified)
                {
                    File.WriteAllText(CONFIG.GetPath("Root") + "Composer_Scratch.txt", this.txtScratch.Text, Encoding.UTF8);
                }
            }
            catch
            {
            }
        }

        internal static void SavePrefs()
        {
            if (oRequestBuilder != null)
            {
                oRequestBuilder.SavePreferences();
            }
        }

        private void tabsBuilder_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.btnBuilderExecute.Enabled = this.tabsBuilder.SelectedTab != this.pageOptions;
            TabPage pageRaw = this.pageRaw;
            TabPage selectedTab = this.tabsBuilder.SelectedTab;
            if (this.tabsBuilder.SelectedTab == this.pageScratch)
            {
                this.EnsureScratch();
            }
        }

        private void txtBuilderURL_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.A))
            {
                this.cbxBuilderURL.SelectAll();
                e.SuppressKeyPress = true;
            }
        }

        private void txtBuilderURL_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;
                this.btnBuilderExecute_Click(this, null);
            }
        }

        private void txtBuilderURL_TextChanged(object sender, EventArgs e)
        {
            if (this.cbxBuilderURL.Text.Length < 1)
            {
                this.cbxBuilderURL.BackColor = Color.Red;
            }
            else if (this.cbxBuilderURL.Text.IndexOf(' ') > -1)
            {
                this.cbxBuilderURL.BackColor = Color.Red;
            }
            else
            {
                this.cbxBuilderURL.BackColor = Color.FromKnownColor(KnownColor.Window);
            }
        }

        private void txtScratch_MouseClick(object sender, MouseEventArgs e)
        {
            if (((e.Button == MouseButtons.Left) && rectLastDblClick.Contains(e.Location)) && (DateTime.Now < dtLastDblClick.AddMilliseconds((double) SystemInformation.DoubleClickTime)))
            {
                dtLastDblClick = DateTime.MinValue;
                this.FloodSelectText();
            }
        }

        private void txtScratch_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                dtLastDblClick = DateTime.Now;
                rectLastDblClick = new Rectangle(e.Location, sizeDblClickArea);
            }
        }
    }
}

